<template>
	<view class="error flexCol">
		<u-empty
		    :icon="pageType !=='notfound' ? errorImage : pageImage"
				:text="pageType !=='notfound' ? '出现错误，请返回重试' : '页面不存在，请返回首页重试'"
		/>
		<u-gap height="20" />
		<navigator
			url="/pages/index/index"
			open-type="switchTab"
			hover-class="navigator-hover"
			class="flexCenter"
		>
			回到首页
		</navigator>
	</view>
</template>

<script>
  import pageImage from '@/static/empty/NullPage.png'
  import errorImage from '@/static/empty/NullData.png'
	export default {
		name: 'Error', // 出错页面
		options: { styleIsolation: 'shared' }, // 父组件设置 options.styleIsolation 可穿透子组件，以及页面
		data() {
			return {
				pageType: '',
				errorImage: errorImage, // 报错图片
				pageImage: pageImage, // 页面不存在图片
			}
		},
		onShow() {
      const routes = getCurrentPages()
      this.pageType = routes[routes.length-1]?.options?.type // 赋值当前页面路径（触发监听
		},
		methods: {
			backHome() {
				uni.switchTab({ url: '/pages/index/index' })
			}
		}
	}
</script>

<style lang="scss" scoped>
.error{
	/deep/ .u-empty{
		uni-image{
			width: 700rpx !important;
			height: 700rpx !important;
		}
	}
}
.navigator-hover{
	color: $uni-color-primary;
}
</style>
